package io.iec.edp.caf.msu.client.discovery;

import io.iec.edp.caf.commons.utils.SpringBeanUtils;
import io.iec.edp.caf.msu.api.client.ServiceUnitInfoDiscovery;
import io.iec.edp.caf.msu.api.entity.ServiceUnitInfo;
import io.iec.edp.caf.msu.api.server.MsuServiceDiscovery;
import io.iec.edp.caf.msu.client.exception.MsuNotFoundException;
import io.iec.edp.caf.msu.client.utils.MsuConstParam;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class ServiceUnitInfoDiscoveryImpl implements ServiceUnitInfoDiscovery {

    private static final int DEFAULT_PORT = 5200;

    public ServiceUnitInfoDiscoveryImpl() {
    }

    @Override
    public List<ServiceUnitInfo> discoveryEnabledServiceUnitInfos() {

        var eventContext = new HashMap<String,String>();
        List<ServiceUnitInfo> infos = null;
        try {
            MsuServiceDiscovery msuServiceDiscovery = SpringBeanUtils.getBean(MsuServiceDiscovery.class);
            infos = msuServiceDiscovery.discoverEnableServiceUnitInfo();
            //LinkedHashMap<String,Object> param = new LinkedHashMap<String, Object>();
            //infos = rpcClient.invoke(type, MsuConstParam.MSU_DISCOVERYSUINFO_SERVICEID, MsuConstParam.MSU_SERVICE_NAME,param,null);
        }  catch (Exception e) {
            log.error("get su info exception",e);
            throw new MsuNotFoundException();
        }

        return infos;

    }

}
